package com.sgb.member.databinding;

import android.graphics.drawable.Drawable;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.databinding.BindingAdapter;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.bumptech.glide.request.target.SimpleTarget;
import com.bumptech.glide.request.transition.Transition;
import com.swgk.core.R;
import com.swgk.core.customview.GlideRoundTransform;

public class BindingAttrAdapter {

    @BindingAdapter(value = {"imageUrlForMember", "memberDefaultPlace"}, requireAll = false)
    public static void imageUrlForMember(ImageView view, String memberImageUrl, Drawable memberDefaultPlace) {
        Glide.with(view.getContext()).load(memberImageUrl).apply(new RequestOptions()
                .placeholder(memberDefaultPlace)
                .fallback(memberDefaultPlace)
                .error(memberDefaultPlace)
                .centerCrop()
        ).into(view);
    }

    @BindingAdapter(value = {"imageUrlForMemberCompany", "memberPlaceholder"}, requireAll = false)
    public static void imageUrlForMemberCompany(ImageView view, String memberImageUrl, Drawable memberPlaceholder) {
        Glide.with(view.getContext()).load(memberImageUrl).apply(new RequestOptions()
                .placeholder(memberPlaceholder)
                .fallback(memberPlaceholder)
                .error(memberPlaceholder)
                .centerCrop()
        ).into(view);
    }

    @BindingAdapter(value = {"roundMember", "roundMemberPlace"}, requireAll = false)
    public static void roundMember(ImageView view, String roundMember, Drawable roundMemberPlace) {
        Glide.with(view.getContext()).load(roundMember).apply(new RequestOptions()
                .placeholder(roundMemberPlace)
                .fallback(roundMemberPlace)
                .error(roundMemberPlace)
                .fitCenter()
                .transform(new GlideRoundTransform(view.getContext(), 4))
        ).into(view);
    }
}
